package org.noote.libs.robot.object3d;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

import org.noote.libs.robot.object3d.helper.Mesh_Axis;
import org.noote.libs.skeleton.Bone;
import org.noote.libs.sogle.LineMesh;
import org.noote.libs.sogle.Mesh;
import org.noote.libs.sogle.Object3D;
import org.noote.libs.sogle.Vector3D;
import org.noote.libs.sogle.helper.Mesh_Box;
import org.noote.libs.sogle.helper.LineMesh_Box;

public class Robot_Bone3D extends Bone {
	
	public ArrayList<Object3D> _listMeshes = new ArrayList<Object3D>();
	
	LineMesh _meshWireBox;
	Mesh_Axis _meshAxe;
	Mesh _meshBox;

	public Robot_Bone3D() {
		super();
	}
	
	public void addMesh(Object3D mesh)
	{
		_listMeshes.add(mesh);
	}
	
	public void createBox(float fSizeX, float fSizeY, float fSizeZ, Vector3D vPosition, float fRed, float fGreen, float fBlue)
	{
		_meshAxe = new Mesh_Axis();
		//_meshAxe.setPosition(vPosition.x, vPosition.y, vPosition.z);
		_meshAxe.setPosition(0, 0, 0);
		
		_meshBox = new Mesh_Box(fSizeX, fSizeY, fSizeZ);
		_meshBox.setPosition(vPosition.x, vPosition.y, vPosition.z);
		_meshBox.setColor(fRed, fGreen, fBlue, 1);
		
		_meshWireBox = new LineMesh_Box(fSizeX, fSizeY, fSizeZ);
		_meshWireBox.setPosition(vPosition.x, vPosition.y, vPosition.z);
		_meshWireBox.setColor(fRed, fGreen, fBlue, 1);
	}

	public void draw(GL10 gl, int type) {

		gl.glPushMatrix();
		gl.glMultMatrixf(getLocalMatrix(), 0);
		if((type&Robot_Skeleton3D._DRAW_WIRED)==Robot_Skeleton3D._DRAW_WIRED)
		{
			if(_meshAxe != null)
				_meshAxe.draw(gl);
			if(_meshWireBox != null)
				_meshWireBox.draw(gl);
		}
		if((type&Robot_Skeleton3D._DRAW_BOX)==Robot_Skeleton3D._DRAW_BOX)
		{
			if(_meshBox!=null)
				_meshBox.draw(gl);
		}
		if((type&Robot_Skeleton3D.DRAW_MESH)==Robot_Skeleton3D.DRAW_MESH)
		{
			for(Object3D mesh : _listMeshes)
			{
				mesh.draw(gl);
			}
		}
		gl.glPopMatrix();
	}	
}
